//
//  CitesTableView.m
//  wtshoppingcite
//
//  Created by TW on 15/5/15.
//  Copyright (c) 2015年 TW. All rights reserved.
//

#import "CitesTableView.h"
#import <BaiduMapAPI/BMapKit.h>
#import "CitesModel.h"

@implementation CitesTableView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    
    self = [super initWithFrame:frame style:style];
    if(self){
        self.backgroundView = nil;
        self.backgroundColor = [UIColor whiteColor];
        self.dataSource = self;
        self.delegate = self;
        self.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    }
    return self;
}


#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 100;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.data count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"poiSearchCell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"poiSearchCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UIImageView *iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 60, 60)];
        iconImageView.image = [UIImage imageNamed:@"commity_near"];
        [cell.contentView addSubview:iconImageView];
        
        
        UILabel *titleLable = [self createLabelWithFrame:CGRectMake(iconImageView.right+10, iconImageView.top-5, 220, 40) text:@"" font:16.0f textAli:NSTextAlignmentLeft textColor:MAIN_BLACK_COLOR];
        titleLable.tag = 100;
        [cell.contentView addSubview:titleLable];
        
        
        UIImageView *addressView = [[UIImageView alloc]initWithFrame:CGRectMake(titleLable.left, titleLable.bottom, 20, 20)];
        addressView.image = [UIImage imageNamed:@"address"];
        [cell.contentView addSubview:addressView];
        
        
        UILabel *subTitleLable = [self createLabelWithFrame:CGRectMake(addressView.right, addressView.top, 180, 20) text:@"" font:14.0f textAli:NSTextAlignmentLeft textColor:MAIN_GRAY_COLOR];
        subTitleLable.tag = 101;
        [cell.contentView addSubview:subTitleLable];

        
    }
    
    if ([_type isEqual:@"推荐"]) {
        
        
        CitesModel *citesModel = [self.data objectAtIndex:indexPath.row];
        NSLog(@"citesModel %@",citesModel);
        
        
        UILabel *titleLable=(UILabel *)[cell.contentView viewWithTag:100];
        titleLable.text = citesModel.comnityName;
        
        UILabel *subTitleLable = (UILabel *)[cell.contentView viewWithTag:101];
        subTitleLable.text = citesModel.address;

        
    }else if([_type isEqual:@"附近"]){

        
        CitesModel *citesModel = [self.data objectAtIndex:indexPath.row];
        NSLog(@"citesModel %@",citesModel);
        
        
        UILabel *titleLable=(UILabel *)[cell.contentView viewWithTag:100];
        titleLable.text = citesModel.comnityName;
        
        UILabel *subTitleLable = (UILabel *)[cell.contentView viewWithTag:101];
        subTitleLable.text = citesModel.address;
    }
    
   
    
    return cell;
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(self.eventsDelegate!= nil  && [self.eventsDelegate respondsToSelector:@selector(basetableView:didSelectRowAtIndexPath:)]){
        [self.eventsDelegate basetableView:self didSelectRowAtIndexPath:indexPath];
    }
    
}

-(UILabel*)createLabelWithFrame:(CGRect)frame text:(NSString*)text font:(int)font textAli:(NSTextAlignment)alig textColor:(UIColor*)tc{
    if(text == nil)
        text = @"";
    UILabel* label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = [UIFont systemFontOfSize:font];
    label.textAlignment = alig;
    label.textColor = tc;
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor clearColor];
    return label;
}

@end

